home *** CD-ROM | disk | FTP | other *** search
- #include "stdio.h"
-
- typedef struct wcb /* --- window control block --- */
- {
- int ulx, /* upper left corner x coordinate */
- uly, /* ditto y coordinate */
- xsize, /* line width of inside of window */
- ysize, /* number of lines inside of window */
- cx, /* current cursor offset in window */
- cy,
- style, /* attribute to be used in window */
- *scrnsave, /* pointer to screen save buffer */
- oldx, /* cursor position when window was */
- oldy; /* opened (used for screen restore) */
- } WINDOW, *WINDOWPTR;
-
- putch(x, y, c,attr)
- int x, y, c,attr;
- {
- gotoxy(x, y, 0);
- vputca(c,0x01, 0, 1);
- }
-
-
- getch(x, y)
- int x, y;
- {
- gotoxy(x, y, 0);
- return(vgetc(0));
- }
-
-
- draw_row(x, y, count, c)
- int x, y, count,c;
- {
- gotoxy(x, y, 0);
- vputca(c,0x07, 0, count);
- }
-
-
- draw_window(x, y, width, height, attrib)
- int x, y, width, height, attrib;
- {
- WINDOWPTR wn;
- int tx, ty,
- xend, yend;
- int *tptr;
- char *calloc();
-
- if ((wn = (WINDOWPTR)calloc(1, sizeof(WINDOW))) == NULL)
- return(NULL);
- else if ((wn->scrnsave = (int *)calloc((width+2) * (height+2), sizeof(int))) == NULL)
- {
- free(wn);
- return(NULL);
- }
- else
- {
- /* store parameters in window control block */
-
- wn->ulx = x;
- wn->uly = y;
- wn->xsize = width;
- wn->ysize = height;
- wn->cx = 1;
- wn->cy = 1;
- wn->style = attrib;
- attrib <<= 8; /* will make things below go quicker */
- wn->oldx = getxy(0) & 255;
- wn->oldy = getxy(0) >> 8;
-
- tptr = wn->scrnsave;
- xend = x + width + 2;
- yend = y + height + 2;
-
- for (ty = y; ty < yend; ty++)
- {
- for (tx = x; tx < xend; tx++)
- *tptr++ = getch(tx, ty);
- }
-
- putch(x, y, 0xda + attrib,attrib); /* ul corner */
- draw_row(x + 1, y, width, 0xc4 + attrib); /* horiz bar */
- putch(x + width + 1, y, 0xbf + attrib,attrib); /* ur corner */
-
- yend = y + height;
-
- for (ty = y+1; ty <= yend; ty++)
- {
- putch(x, ty, 0xb3 + attrib,attrib); /* draw the sides */
- putch(x+width+1, ty, 0xb3 + attrib,attrib);
- }
-
- putch(x, y + height + 1, 0xc0 + attrib,attrib); /* ll corner */
- draw_row(x + 1, y + height + 1, width, 0xc4 + attrib); /* horiz bar */
- putch(x + width + 1, y + height + 1, 0xd9 + attrib,attrib); /* lr corner */
-
- clr_window(wn);
-
- return(wn);
- }
- }
-
-
- remove_window(wn)
- WINDOWPTR wn;
- {
- int tx, ty,
- xend, yend;
- int *tptr;
-
- tptr = wn->scrnsave;
- xend = wn->ulx + wn->xsize + 2;
- yend = wn->uly + wn->ysize + 2;
-
- for (ty = wn->uly; ty < yend; ty++)
- {
- for (tx = wn->ulx; tx < xend; tx++)
- putch(tx, ty, *tptr++,0x01);
- }
-
- gotoxy(wn->oldx, wn->oldy, 0);
-
- free(wn->scrnsave);
- free(wn);
- }
-
-
- write_text(wn, attr, string)
- WINDOWPTR wn;
- char *string;
- int attr;
- {
- int tx, ty, xend;
-
- if (wn->cy > wn->ysize)
- {
- delete_row(wn, 1);
- --wn->cy;
- }
-
- if (wn->cx > 0)
- tx = wn->ulx + wn->cx;
- else
- {
- if (-wn->cx < strlen(string))
- string -= wn->cx;
- else
- *string = '\0';
- tx = wn->ulx + 1;
- }
- xend = wn->ulx + wn->xsize + 1;
- ty = wn->uly + wn->cy;
- while ((tx < xend) && *string)
- {
- gotoxy(tx++, ty, 0);
- vputca(*string++,attr, 0, 1);
- }
- ++wn->cy; /* move the internal cursor to the next line */
- }
-
-
- insert_row(wn, row)
- WINDOWPTR wn;
- int row;
- {
- int scrlwn[4];
-
- /* calculate corners of the scrolling window */
-
- scrlwn[0] = wn->ulx + 1; /* ulx */
- scrlwn[1] = wn->uly + row; /* uly */
- scrlwn[2] = wn->ulx + wn->xsize; /* lrx */
- scrlwn[3] = wn->uly + wn->ysize; /* lry */
-
- scrldn(scrlwn, 1, wn->style);
- }
-
-
- delete_row(wn, row)
- WINDOWPTR wn;
- int row;
- {
- int scrlwn[4];
-
- /* calculate corners of the scrolling window */
-
- scrlwn[0] = wn->ulx + 1; /* ulx */
- scrlwn[1] = wn->uly + row; /* uly */
- scrlwn[2] = wn->ulx + wn->xsize; /* lrx */
- scrlwn[3] = wn->uly + wn->ysize; /* lry */
-
- scrlup(scrlwn, 1, wn->style);
- }
-
-
- clr_window(wn)
- WINDOWPTR wn;
- {
- int scrlwn[4];
-
- /* calculate corners of the scrolling window */
-
- scrlwn[0] = wn->ulx + 1; /* ulx */
- scrlwn[1] = wn->uly + 1; /* uly */
- scrlwn[2] = wn->ulx + wn->xsize; /* lrx */
- scrlwn[3] = wn->uly + wn->ysize; /* lry */
-
- scrlup(scrlwn, 0, wn->style);
- wn->cx = 1;
- wn->cy = 1;
- }
-
-
- gotoxy(x, y, page)
- int x, y, page;
- {
- unsigned inr[4], outr[4];
-
- inr[3] = y;
- inr[3] <<= 8;
- inr[3] |= x;
- inr[1] = page;
- inr[1] <<= 8;
- inr[0] = 0x200;
- sysint(0x10, &inr, &outr);
-
- }
-
- vputca(chr,attr, page, count)
- int chr,page, count,attr;
- {
- unsigned inr[4], outr[4];
-
- inr[1] = page; /* bh */
- inr[1] <<= 8;
- inr[1] |= attr; /* bl */
- inr[2] = count; /* cx */
- inr[0] = 9; /* ah */
- inr[0] <<= 8;
- inr[0] |= chr & 0xff; /* al */
- sysint(0x10, &inr, &outr);
- }
-
- vgetc(page)
- int page;
- {
- unsigned inr[4], outr[4];
-
- inr[1] = page;
- inr[1] <<= 8;
- inr[0] = 0x800;
- sysint(0x10, &inr, &outr);
- return(outr[0]);
-
- }
-
- getxy(page)
- int page;
- {
- unsigned inr[4], outr[4];
-
- inr[1] = page;
- inr[1] <<= 8;
- inr[0] = 0x300;
- sysint(0x10, &inr, &outr);
- return(outr[3]);
-
- }
-
- vputc(chr, page, count)
- int chr, page, count;
- {
- unsigned inr[4], outr[4];
- char attr='7';
- inr[1] = page; /* bh */
- inr[1] <<= 8;
- inr[1] |= attr & 0xff;
- inr[2] = count; /* cx */
- inr[0] = 10; /* ah */
- inr[0] <<= 8;
- inr[0] |= chr & 0xff; /* al */
- sysint(0x10, &inr, &outr);
-
- }
-
- scrlup(window, count, attrib)
- int window[4], count, attrib;
- {
- unsigned inr[4], outr[4];
-
- inr[1] = attrib;
- inr[1] <<= 8;
- inr[0] = 0x600;
- inr[0] |= count;
- inr[2] = window[1];
- inr[2] <<= 8;
- inr[2] |= window[0];
- inr[3] = window[3];
- inr[3] <<= 8;
- inr[3] |= window[2];
- sysint(0x10, &inr, &outr);
-
- }
-
- scrldn(window, count, attrib)
- int window[4], count, attrib;
- {
- unsigned inr[4], outr[4];
-
- inr[1] = attrib;
- inr[1] <<= 8;
- inr[0] = 0x700;
- inr[0] |= count;
- inr[2] = window[1];
- inr[2] <<= 8;
- inr[2] |= window[0];
- inr[3] = window[3];
- inr[3] <<= 8;
- inr[3] |= window[2];
- sysint(0x10, &inr, &outr);
-
- }
-
-